package com.bawei.module_home.ui.visitor

import android.os.Bundle
import android.util.Log
import androidx.activity.enableEdgeToEdge
import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.recyclerview.widget.LinearLayoutManager
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.bawei.lib_common.Router
import com.bawei.lib_common.base.BaseActivity
import com.bawei.lib_common.base.BaseViewModel
import com.bawei.lib_common.base.state.Empty
import com.bawei.lib_common.base.state.Failed
import com.bawei.lib_common.base.state.Loading
import com.bawei.lib_common.base.state.Success
import com.bawei.lib_common.observeWithLifecycle
import com.bawei.lib_common.utils.ToastUtils
import com.bawei.module_home.R
import com.bawei.module_home.adapter.DeviceAdapter
import com.bawei.module_home.adapter.StatusAdapter
import com.bawei.module_home.adapter.VisitorAdapter
import com.bawei.module_home.databinding.ActivityVisitorManagerBinding
import com.bawei.module_home.http.HomeServiceViewModel
import com.bawei.module_home.model.StatusModel
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
@Route(path = Router.VISITOR_MANAGER_PAGE)
class VisitorManagerActivity : BaseActivity<BaseViewModel,ActivityVisitorManagerBinding>() {
    override val mLayoutResId: Int
        get() = R.layout.activity_visitor_manager
    private val dataList = mutableListOf<StatusModel>()
    private val mViewModel : HomeServiceViewModel by viewModels()
    private val mAdapter=VisitorAdapter()
    override fun initView() {
        super.initView()
        // 初始化数据
        dataList.add(StatusModel("全部状态", true)) // 默认“全部状态”选中
        dataList.add(StatusModel("待审核"))
        dataList.add(StatusModel("已通过"))
        dataList.add(StatusModel("驳回"))


        var adapter = StatusAdapter(dataList) { position ->
            // 处理 item 点击事件，比如根据选中项切换数据展示等逻辑
            ToastUtils.showLong(this,"选中了：${dataList[position].statusText}")
        }
        mBinding.rvStatus.adapter = adapter
        mBinding.rvStatus.layoutManager = LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false)


        mBinding.rvList.adapter=mAdapter
        mBinding.rvList.layoutManager = LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false)
        mBinding.back.setOnClickListener {
            finish()
        }
        mBinding.btnAdd.setOnClickListener {
            ARouter.getInstance().build(Router.VISITOR_PAGE).navigation()
        }
    }

    override fun initData() {
        mViewModel.getVisitor()
    }

    override fun initListener() {
        mViewModel.getVisitorList.observeWithLifecycle(this){
            when(it){
                Empty -> {}
                is Failed -> {
                    ToastUtils.showLong(this,it.message)
                }
                Loading -> {

                }
                Success -> {
                    mAdapter.setData(mViewModel.visitorList)
                    Log.d("LYJ", "initListener: success")
                    //mAdapter.setData(mViewModel.visitorList)
                }
            }
        }
    }

    override fun initStatusBar() {

    }
    override fun onResume() {
        super.onResume()
        mViewModel.getVisitor()
    }
}